package com.maiji.cloud.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.maiji.cloud.config.MyRedisConfig;
import com.maiji.cloud.entities.login.AppUser;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.shopingmall.AddExchangeLogReqDto;
import com.maiji.cloud.request.shopingmall.GetExchangeLogReqDto;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.Status;
import com.maiji.cloud.response.shopingmall.FreeDiscountCouponListResDto;
import com.maiji.cloud.response.shopingmall.GetDiscountCouponListResData;
import com.maiji.cloud.response.shopingmall.GetDiscountCouponListResDto;
import com.maiji.cloud.response.shopingmall.GetExchangeLogResDto;
import com.maiji.cloud.response.shopingmall.HaveDiscountCouponListResData;
import com.maiji.cloud.service.CouponsService;
import com.maiji.cloud.utils.RedisUtil;

/**
 * 优惠券
 * Description:  
 * @author zhanglr  
 * @date 2019年6月24日
 */
@RestController
@RequestMapping("/coupons/")
public class CouponsController {
	 Logger logger = LoggerFactory.getLogger(CouponsController.class);
	
	 @Autowired
	private CouponsService couponsService;
	/**
	 * 获去可兑换优惠券列表
	 * @return
	 */
	@PostMapping("getDiscountCouponList")
	public GetDiscountCouponListResDto getDiscountCouponList(){
		return couponsService.getDiscountCouponList();
	}
	
	/**
	 * 获取积分兑换商品记录列表
	 * @param getExchangeLogReqDto
	 * @return
	 */
	@PostMapping("getExchangeLogList")
	public GetExchangeLogResDto getExchangeLogList(@RequestBody GetExchangeLogReqDto getExchangeLogReqDto){
		return couponsService.getExchangeLogList(getExchangeLogReqDto);
	}
	
	/**
	 * 用户兑换商品或优惠券
	 * @param param
	 * @return
	 */
	@PostMapping("addExchangeLog")
	public BaseDataResDto addExchangeLog(@RequestBody AddExchangeLogReqDto param){
		logger.info("CouponsController.addExchangeLog ,param is {}",JSON.toJSONString(param));
		return couponsService.addExchangeLog(param);
	}

	/**
	 * 用户已经领取优惠券列表
	 * @return
	 */
	@PostMapping("getUsableDiscountCouponList")
	public BaseDataResDto<List<GetDiscountCouponListResData>> getUsableDiscountCouponList(@RequestBody BaseDataReqDto<Double> param , @RequestHeader String maijiToken){
		logger.info("CouponsController.getUsableDiscountCouponList ,maijiToken is {}",maijiToken);
		Double money = param.getData();
		return couponsService.getUsableDiscountCouponList(money,maijiToken);
	}
	
	/**
	 * 1：未使用，2：已使用：3：已过期优惠券列表
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("getHaveDiscountCouponList")
	public BaseDataResDto<List<HaveDiscountCouponListResData>> getHaveDiscountCouponList(@RequestBody BaseDataReqDto<Integer> param , @RequestHeader String maijiToken){
		logger.info("CouponsController.getHaveDiscountCouponList ,param is {} ,maijiToken is {}",JSON.toJSONString(param),maijiToken);
		return couponsService.getHaveDiscountCouponList(param,maijiToken);
	}
	

	/**
	* 获取免费优惠券列表
	 * @return
	 */
	@PostMapping("getfreeDiscountCouponList")
	public FreeDiscountCouponListResDto getfreeDiscountCouponList(@RequestBody BaseDataReqDto<Double> param ){
		logger.info("CouponsController.getfreeDiscountCouponList ");
		Double money = param.getData();
		return couponsService.getfreeDiscountCouponList(money);
	}

	/**
	 * 未领取优惠券
	 * @return
	 */
	@PostMapping("noPossessDiscountCouponList")
	public BaseDataResDto<List<GetDiscountCouponListResData>> noPossessDiscountCouponList(@RequestBody BaseDataReqDto<Double> param ,@RequestHeader String maijiToken){
		logger.info("CouponsController.noPossessDiscountCouponList ,maijiToken is {}",maijiToken);
		Double money = param.getData();
		return couponsService.noPossessDiscountCouponList(money ,maijiToken);
	}
	
}
